<?php

namespace app\admin\controller;

use app\admin\model\AdminLog;
use app\common\controller\Backend;
use think\Config;
use think\Hook;
use think\Validate;

/**
 * 后台首页
 * @internal
 */
class Index extends Backend
{

    protected $noNeedLogin = ['login'];
    protected $noNeedRight = ['index', 'logout'];
    protected $layout = '';

    public function _initialize()
    {
        parent::_initialize();
        //移除HTML标签
        $this->request->filter('trim,strip_tags,htmlspecialchars');
    }

    /**
     * 后台首页
     */
    public function index()
    {
        //左侧菜单
        list($menulist, $navlist, $fixedmenu, $referermenu) = $this->auth->getSidebar([
            'dashboard' => 'hot',
            'addon'     => ['new', 'red', 'badge'],
            'auth/rule' => __('Menu'),
            'general'   => ['new', 'purple'],
        ], $this->view->site['fixedpage']);
        $action = $this->request->request('action');
        if ($this->request->isPost()) {
            if ($action == 'refreshmenu') {
                $this->success('', null, ['menulist' => $menulist, 'navlist' => $navlist]);
            }
        }
        $this->view->assign('menulist', $menulist);
        $this->view->assign('navlist', $navlist);
        $this->view->assign('fixedmenu', $fixedmenu);
        $this->view->assign('referermenu', $referermenu);
        $this->view->assign('title', __('Home'));
        return $this->view->fetch();
    }

    /**
     * 管理员登录
     */
    public function login()
    {
        $url = $this->request->get('url', 'index/index');
        if ($this->auth->isLogin()) {
            $this->success(__("You've logged in, do not login again"), $url);
        }
        if ($this->request->isPost()) {
            $username = $this->request->post('username');
            $password = $this->request->post('password');
            $keeplogin = $this->request->post('keeplogin');
            $token = $this->request->post('__token__');
            $rule = [
                'username'  => 'require|length:3,30',
                'password'  => 'require|length:3,30',
                '__token__' => 'require|token',
            ];
            $data = [
                'username'  => $username,
                'password'  => $password,
                '__token__' => $token,
            ];
            if (Config::get('fastadmin.login_captcha')) {
                $rule['captcha'] = 'require|captcha';
                $data['captcha'] = $this->request->post('captcha');
            }
            $validate = new Validate($rule, [], ['username' => __('Username'), 'password' => __('Password'), 'captcha' => __('Captcha')]);
            $result = $validate->check($data);
            if (!$result) {
                $this->error($validate->getError(), $url, ['token' => $this->request->token()]);
            }
            AdminLog::setTitle(__('Login'));
            $result = $this->auth->login($username, $password, $keeplogin ? 86400 : 0);
            if ($result === true) {
                Hook::listen("admin_login_after", $this->request);
                $this->success(__('Login successful'), $url, ['url' => $url, 'id' => $this->auth->id, 'username' => $username, 'avatar' => $this->auth->avatar]);
            } else {
                $msg = $this->auth->getError();
                $msg = $msg ? $msg : __('Username or password is incorrect');
                $this->error($msg, $url, ['token' => $this->request->token()]);
            }
        }

        // 根据客户端的cookie,判断是否可以自动登录
        if ($this->auth->autologin()) {
            $this->redirect($url);
        }
        $background = Config::get('fastadmin.login_background');
        $background = stripos($background, 'http') === 0 ? $background : config('site.cdnurl') . $background;
        $this->view->assign('background', $background);
        $this->view->assign('title', __('Login'));
        Hook::listen("admin_login_init", $this->request);
        return $this->view->fetch();
    }

    /**
     * 注销登录
     */
    public function logout()
    {
        $this->auth->logout();
        Hook::listen("admin_logout_after", $this->request);
        $this->success(__('Logout successful'), 'index/login');
    }

    public function test(){
       // $str='<img size=1500x2322>//img.alicdn.com/imgextra/i3/1732742584/O1CN01mdUcuj1UxW3OGGWpd_!!1732742584.jpg</img><img size=1500x554>//img.alicdn.com/imgextra/i3/1732742584/O1CN01mJA9bo1UxW3JZtpzX_!!1732742584.jpg</img><img size=790x969>//img.alicdn.com/imgextra/i4/1732742584/O1CN01eMMVr91UxW2gI2KYQ_!!1732742584.jpg</img><img size=1500x2107>//img.alicdn.com/imgextra/i3/1732742584/O1CN01UtuJw91UxW3JKk5ka_!!1732742584.jpg</img><img size=1500x2322>//img.alicdn.com/imgextra/i4/1732742584/O1CN01xeA4dM1UxW3C6bf04_!!1732742584.jpg</img><img size=1500x915>//img.alicdn.com/imgextra/i1/1732742584/O1CN01GcrJhN1UxW3M4E4Gy_!!1732742584.jpg</img><img size=790x729>//img.alicdn.com/imgextra/i2/1732742584/O1CN019tOd0l1UxW3WY6OCa_!!1732742584.jpg</img><img size=1500x1783>//img.alicdn.com/imgextra/i2/1732742584/O1CN01Ox2nel1UxW2sYEKVc_!!1732742584.jpg</img><img size=1500x1376>//img.alicdn.com/imgextra/i3/1732742584/O1CN01jVetTh1UxW38QS7h1_!!1732742584.jpg</img><img size=790x720>//img.alicdn.com/imgextra/i3/1732742584/O1CN01HMxO621UxW2AqcmbH_!!1732742584.jpg</img><img size=790x574>//img.alicdn.com/imgextra/i3/1732742584/O1CN01ZZlTbR1UxW2CxstZo_!!1732742584.jpg</img><img size=1500x1117>//img.alicdn.com/imgextra/i1/1732742584/O1CN018RzAW21UxW2xI4TGc_!!1732742584.jpg</img><img size=1500x2322>//img.alicdn.com/imgextra/i2/1732742584/O1CN01eIqPg11UxW3JEdDFO_!!1732742584.jpg</img><img size=1500x2322>//img.alicdn.com/imgextra/i1/1732742584/O1CN01MmhAkx1UxW3FC8nJr_!!1732742584.jpg</img><img size=1500x2322>//img.alicdn.com/imgextra/i2/1732742584/O1CN01jx5QkN1UxW3Mr2ALE_!!1732742584.jpg</img><img size=1500x1973>//img.alicdn.com/imgextra/i2/1732742584/O1CN01io4TBJ1UxW3KSzwHL_!!1732742584.jpg</img><img size=790x830>//img.alicdn.com/imgextra/i3/1732742584/O1CN010eyzTY1UxW0tdXu4S_!!1732742584.jpg</img><img size=790x939>//img.alicdn.com/imgextra/i1/1732742584/O1CN014g39JZ1UxW0nxn2oF_!!1732742584.jpg</img><img size=790x1128>//img.alicdn.com/imgextra/i4/1732742584/O1CN01hF5B8G1UxW0pqvuTm_!!1732742584.jpg</img><img size=790x858>//img.alicdn.com/imgextra/i3/1732742584/O1CN01jU28Si1UxW0pfHoyJ_!!1732742584.jpg</img><img size=790x867>//img.alicdn.com/imgextra/i4/1732742584/O1CN01SyTWn51UxW0nxmZio_!!1732742584.jpg</img><img size=790x688>//img.alicdn.com/imgextra/i3/1732742584/O1CN01gHSCrs1UxW0mgVzhO_!!1732742584.jpg</img><img size=790x744>//img.alicdn.com/imgextra/i1/1732742584/O1CN0166Tmn61UxW0neuUBT_!!1732742584.jpg</img><img size=790x876>//img.alicdn.com/imgextra/i2/1732742584/O1CN01mtGizZ1UxW0newMYw_!!1732742584.jpg</img><img size=1500x2322>//img.alicdn.com/imgextra/i1/1732742584/O1CN01DFsQtn1UxW0pr7vg3_!!1732742584.jpg</img><img size=1500x172>//img.alicdn.com/imgextra/i1/1732742584/O1CN01AozlC31UxW0r0HknW_!!1732742584.jpg</img><img size=790x1102>//img.alicdn.com/imgextra/i1/1732742584/O1CN01nhIldf1UxW0sZtFsU_!!1732742584.jpg</img><img size=790x1089>//img.alicdn.com/imgextra/i4/1732742584/O1CN015CUiOO1UxW0rdiWQM_!!1732742584.jpg</img><img size=1500x2322>//img.alicdn.com/imgextra/i1/1732742584/O1CN017bImFI1UxW0ny1PZy_!!1732742584.jpg</img><img size=1500x94>//img.alicdn.com/imgextra/i3/1732742584/O1CN01NATUJu1UxW0rdwgmK_!!1732742584.jpg</img><img>//img.alicdn.com/imgextra/i4/1732742584/O1CN01hwclce1UxW0newQhG_!!1732742584.jpg</img>';

       // dump($strarr);
        //$str =strip_tags($str);

        $a='1111.222';

        dump(is_numeric($a));
    }

}
